# pipepanic
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../func
. ../build.conf

URL=http://www.users.waitrose.com/~thunor/pipepanic/dload
PKG=pipepanic
SRC_VER=0.1.3-source
VER=0.1.3
COMP=tar.gz
DESC="A classic game where you join the pipes"
DEPS=+sdl
CAT=Fun
DESKTOP=pipepanic.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)	
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not	

ARCH=$(uname -m)
case $ARCH in
 *64) 	LIBDIR=$LIBCONF64 ;;
 arm*)	LIBDIR=$LIBCONFarm;;
 *) 	LIBDIR=$LIBCONF32 ;;
esac

build() {
	mv ${PKG}-${SRC_VER} ${PKG}-${VER}
	cd ${PKG}-${VER}
	make $MKFLG
	[ "$?" -eq 0 ] || exit
	cd -
}
	
package() {
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/usr/share/pipepanic
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/usr/bin
	cat > pipepanic << _EOF
#!/bin/sh
cd /usr/share/$PKG
./pipepanic
cd -
_EOF
	install -m 0755 $PKG ./${PKG}-${VER}-${ARCH}/usr/bin
	install -s -m 0755 ${PKG}-${VER}/$PKG ./${PKG}-${VER}-${ARCH}/usr/share/pipepanic
	for extra in *.bmp *.xcf *.png COPYING* AUTHORS VERSION; do
		echo "installing $extra"
		install -m 0644 ${PKG}-${VER}/$extra ./${PKG}-${VER}-${ARCH}/usr/share/pipepanic
	done
	# add this recipe
	install -d -m 0755 ./${PKG}_DEV-${VER}-${ARCH}/usr/src/dev
	cat ${PKG}.petbuild > ./${PKG}_DEV-${VER}-${ARCH}/usr/src/dev/${PKG}-build-recipe
	if [ -f "$DESKTOP" ];then
		install -d -m 0755 ./${PKG}-${VER}-${ARCH}/usr/share/applications
		cat $DESKTOP > ./${PKG}-${VER}-${ARCH}/usr/share/applications/$DESKTOP
	fi
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/usr/share/pixmaps
	install -m 0644 PipepanicIcon48.png ./${PKG}-${VER}-${ARCH}/usr/share/pixmaps
	# delete any icon cache or library cache
	find ./${PKG}-${VER}-${ARCH} -type f -name '*cache' -delete
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./${PKG}-${VER}-${ARCH}/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./${PKG}-${VER}-${ARCH}/
	for p in $(ls|grep "\-${ARCH}"|grep -v "files$") ; do
		case $p in
			*_DEV*) DESC="$PKG development"; DEPS=+${PKG} ;;
			*_DOC*) DESC="$PKG documentation"; DEPS=+${PKG} ;;
			*_NLS*) DESC="$PKG locales"; DEPS=+${PKG} ;;
		esac	
		echo "packaging $p"	
		dir2pet -x -s -w="$DESC" -d="$DEPS" -c="$CAT" -p=${p} 2>&1 >/dev/null
		rm -r $p
		mv ${p}.pet ../0pets_out
	done
	#rm -r ${PKG}-install
	rm -r ${PKG}-${VER}
	rm ${PKG}
	#mv -f *.files ../0logs
	echo "done!"
}

# main
retrieve ${PKG}-${SRC_VER}.${COMP}
extract ${PKG}-${SRC_VER}.${COMP}
build
package	
